In [1]:
import strym
from strym import strymread
from strym import phasespace
print(strym.__version__)

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
Loading BokehJS ...
0.1.7

Analyzing RAV4's Data from 5th March 2020

In [2]:
dbcfile = '/home/ivory/VersionControl/Jmscslgroup/strym/examples/newToyotacode.dbc'
datafolder = "/home/ivory/CyverseData/JmscslgroupData/PandaData/2020_03_05/"
import glob
csvlist = glob.glob(datafolder+"*.csv")
In [3]:
r =strymread(csvfile=csvlist[0], dbcfile=dbcfile)
speed = r.speed()
strym.plt_ts(speed, title = "Speed [km/h] Timeseries plot")

I will clip first 250 seconds as during first 250 seconds, vehicle was not vehicle, evident from speed plot above.

In [4]:
message_subset = r.msg_subset(time=(250, r.triptime()))
r_subset = strymread(csvfile=message_subset, dbcfile=dbcfile)
speed = r_subset.speed()
strym.plt_ts(speed, title = "Speed [km/h] Timeseries plot")
In [5]:
speed['Message'] = speed['Message']*(5.0/18.0)
strym.plt_ts(speed, title = "Speed [m/s] Timeseries plot")

Perform slicing: slice dataset in to duration of 30 seconds

In [6]:
r_subsets = []
time_increment = 30
init_time = 0
triptime = r_subset.triptime()
while (init_time + time_increment) <= triptime:
    msg_slice = r_subset.msg_subset(time=(init_time, init_time + time_increment))
    r_new = strymread(csvfile=msg_slice, dbcfile=dbcfile)
    r_subsets.append(r_new)
    init_time = init_time + time_increment

Plot phase-space diagram and histogram of distance from centroid for every slice

In [7]:
for subsets in r_subsets:
    accelx = subsets.accelx()
    speed = subsets.speed()
    # Convert Km/h to m/s
    speed['Message'] = speed['Message']*(5.0/18.0)
    print("\n----------------------------\n")
    print("Covering trip times from {} to {}".format(subsets.start_time(), subsets.end_time()))
    re_speed, re_accelx = strym.ts_sync(speed, accelx, rate="first")
    ps = phasespace(dfx=re_speed, dfy=re_accelx, resample_type="first")
    ps.phaseplot(title='Phase-space plot of speed-acceleration for Rav4 Data from 5th March 2020 Drive',
                xlabel='speed', ylabel='acceleration')
    ps.centroidplot
    print("Average Centroid Distane of cluster is {}".format(ps.acd))
----------------------------

Covering trip times from Thu Mar  5 08:27:40 2020 to Thu Mar  5 08:28:10 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 6.87585039790307

----------------------------

Covering trip times from Thu Mar  5 08:28:10 2020 to Thu Mar  5 08:28:40 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 23.80330387013879

----------------------------

Covering trip times from Thu Mar  5 08:28:40 2020 to Thu Mar  5 08:29:10 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 61.77853550559263

----------------------------

Covering trip times from Thu Mar  5 08:29:10 2020 to Thu Mar  5 08:29:40 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 84.68699589936988

----------------------------

Covering trip times from Thu Mar  5 08:29:40 2020 to Thu Mar  5 08:30:10 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 137.70733835615115

----------------------------

Covering trip times from Thu Mar  5 08:30:10 2020 to Thu Mar  5 08:30:40 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 462.5678663348434

----------------------------

Covering trip times from Thu Mar  5 08:30:40 2020 to Thu Mar  5 08:31:10 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 231.89565650742722

----------------------------

Covering trip times from Thu Mar  5 08:31:10 2020 to Thu Mar  5 08:31:40 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 530.2217855216616

----------------------------

Covering trip times from Thu Mar  5 08:31:40 2020 to Thu Mar  5 08:32:10 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 139.11279012617774

----------------------------

Covering trip times from Thu Mar  5 08:32:10 2020 to Thu Mar  5 08:32:40 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 901.343920212635

----------------------------

Covering trip times from Thu Mar  5 08:32:40 2020 to Thu Mar  5 08:33:10 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 228.49200589065754

----------------------------

Covering trip times from Thu Mar  5 08:33:10 2020 to Thu Mar  5 08:33:40 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 663.526388766679

----------------------------

Covering trip times from Thu Mar  5 08:33:40 2020 to Thu Mar  5 08:34:10 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 0.0

----------------------------

Covering trip times from Thu Mar  5 08:34:10 2020 to Thu Mar  5 08:34:40 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 0.0

----------------------------

Covering trip times from Thu Mar  5 08:34:40 2020 to Thu Mar  5 08:35:10 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 199.36444469579865

----------------------------

Covering trip times from Thu Mar  5 08:35:10 2020 to Thu Mar  5 08:35:40 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 2.386525631302482

----------------------------

Covering trip times from Thu Mar  5 08:35:40 2020 to Thu Mar  5 08:36:10 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 131.0724237563401

----------------------------

Covering trip times from Thu Mar  5 08:36:10 2020 to Thu Mar  5 08:36:40 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 48.282910368278195

----------------------------

Covering trip times from Thu Mar  5 08:36:40 2020 to Thu Mar  5 08:37:10 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 0.0

----------------------------

Covering trip times from Thu Mar  5 08:37:10 2020 to Thu Mar  5 08:37:40 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 149.02778345905247

----------------------------

Covering trip times from Thu Mar  5 08:37:40 2020 to Thu Mar  5 08:38:10 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 3.248376709024835

----------------------------

Covering trip times from Thu Mar  5 08:38:10 2020 to Thu Mar  5 08:38:40 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 132.80997310619364

----------------------------

Covering trip times from Thu Mar  5 08:38:40 2020 to Thu Mar  5 08:39:10 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 6.76930253408322

----------------------------

Covering trip times from Thu Mar  5 08:39:10 2020 to Thu Mar  5 08:39:40 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 175.65452034712243

----------------------------

Covering trip times from Thu Mar  5 08:39:40 2020 to Thu Mar  5 08:40:10 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 0.0

----------------------------

Covering trip times from Thu Mar  5 08:40:10 2020 to Thu Mar  5 08:40:40 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 193.75163234151216

----------------------------

Covering trip times from Thu Mar  5 08:40:40 2020 to Thu Mar  5 08:41:10 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 31.599271964555367

----------------------------

Covering trip times from Thu Mar  5 08:41:10 2020 to Thu Mar  5 08:41:40 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 232.11245330753547

----------------------------

Covering trip times from Thu Mar  5 08:41:40 2020 to Thu Mar  5 08:42:10 2020
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 182.14827374608657

Analyzing Ring Road Data from 28th July 2016

In [8]:
speedfiles = [['/home/ivory/CyverseData/JmscslgroupData/ARED/2016-07-28/data_by_test/Bag Files/test3_09-23-59/catvehicle-vel.csv'],
 ['/home/ivory/CyverseData/JmscslgroupData/ARED/2016-07-28/data_by_test/Bag Files/test7_11-07-25/catvehicle-vel.csv'],
 ['/home/ivory/CyverseData/JmscslgroupData/ARED/2016-07-28/data_by_test/Bag Files/test6_10-47-54/catvehicle-vel.csv'],
 ['/home/ivory/CyverseData/JmscslgroupData/ARED/2016-07-28/data_by_test/Bag Files/test8_12-09-17/catvehicle-vel.csv'],
 ['/home/ivory/CyverseData/JmscslgroupData/ARED/2016-07-28/data_by_test/Bag Files/test5_10-17-31/catvehicle-vel.csv'],
 ['/home/ivory/CyverseData/JmscslgroupData/ARED/2016-07-28/data_by_test/Bag Files/test9_12-30-55/catvehicle-vel.csv'],
 ['/home/ivory/CyverseData/JmscslgroupData/ARED/2016-07-28/data_by_test/Bag Files/test10_12-49-51/catvehicle-vel.csv'],
 ['/home/ivory/CyverseData/JmscslgroupData/ARED/2016-07-28/data_by_test/Bag Files/test4_09-41-04/catvehicle-vel.csv']]
In [9]:
speed28 = [None]*len(speedfiles)
for i, s in enumerate(speedfiles):
    speed28[i] = pd.read_csv(s[0])
    speed28[i].drop(speed28[i].columns.difference(['Time', 'LinearX']), 1, inplace=True)
    speed28[i].rename(columns = {'LinearX':'Message'}, inplace = True) 
In [10]:
fig, ax  = strym.create_fig(1)
ax = ax[0]
ax.scatter(speed28[4]['Time'], speed28[4]['Message'], c=speed28[4]['Time'] , s= 8)
ax.set_title('Speed of ' + speedfiles[4][0])
ax.set_xlabel("Time")
ax.set_ylabel("Speed [m/s]")
plt.show()
In [11]:
accel = strym.differentiate(speed28[4])
accel_denoised = strym.denoise(accel,window_size=20 )
In [12]:
fig, ax  = strym.create_fig(1)
ax = ax[0]
plt.rcParams["figure.figsize"] = (14,6)
ax.plot(accel['Time'], accel['Message'])
ax.plot(accel_denoised['Time'], accel_denoised['Message'])
plt.title('Acceleration')
plt.legend(["Original Acceleration (m/s^2)","Denoised Acceleration (m/s^2)" ])
Out[12]:
<matplotlib.legend.Legend at 0x7fa1347ea990>
In [14]:
speed_split, split = strym.split_ts(speed28[4], by = 30)

plt.show()
for df in split:
    print("\n----------------------------\n")
    print("Covering trip times from {} to {}".format(strym.dateparse(df['Time'].iloc[0]), strym.dateparse(df['Time'].iloc[-1])))
    accel_split = strym.differentiate(df)
    accel_split_denoised = strym.denoise(accel_split, window_size=20)
    ps = phasespace(dfx=df, dfy=accel_split_denoised, resample_type="first")
    ps.phaseplot(title='Phase-space plot of speed-acceleration for Ring Road Experiment (July 28, 2020)',
                xlabel='speed', ylabel='acceleration')
    ps.centroidplot( xlabel='Centroid Distance', ylabel='Counts')
    print("Average Centroid Distane of cluster is {}".format(ps.acd))
----------------------------

Covering trip times from 2016-07-28 10:17:31:706100 to 2016-07-28 10:18:01:705900
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 429.61725986538573

----------------------------

Covering trip times from 2016-07-28 10:18:01:753900 to 2016-07-28 10:18:31:752600
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 461.93175411387233

----------------------------

Covering trip times from 2016-07-28 10:18:31:805700 to 2016-07-28 10:19:01:805300
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 15.75146049380393

----------------------------

Covering trip times from 2016-07-28 10:19:01:850900 to 2016-07-28 10:19:31:850100
Average Centroid Distane of cluster is 0.003079825658499438

----------------------------

Covering trip times from 2016-07-28 10:19:31:904000 to 2016-07-28 10:20:01:903300
Average Centroid Distane of cluster is 13.517322436304603

----------------------------

Covering trip times from 2016-07-28 10:20:01:950900 to 2016-07-28 10:20:31:950200
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 0.6509367263694094

----------------------------

Covering trip times from 2016-07-28 10:20:32:003500 to 2016-07-28 10:21:02:002900
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 0.29573222052384657

----------------------------

Covering trip times from 2016-07-28 10:21:02:048400 to 2016-07-28 10:21:32:047700
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 0.028731628870910124

----------------------------

Covering trip times from 2016-07-28 10:21:32:101400 to 2016-07-28 10:22:02:100500
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 0.022941138428577233

----------------------------

Covering trip times from 2016-07-28 10:22:02:148300 to 2016-07-28 10:22:32:147900
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 2.8511797572379685

----------------------------

Covering trip times from 2016-07-28 10:22:32:201200 to 2016-07-28 10:23:02:200600
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 13.811911586011638

----------------------------

Covering trip times from 2016-07-28 10:23:02:247200 to 2016-07-28 10:23:32:200000
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 11.071075947245374

----------------------------

Covering trip times from 2016-07-28 10:23:32:247500 to 2016-07-28 10:24:02:247000
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 0.985000799536208

----------------------------

Covering trip times from 2016-07-28 10:24:02:298200 to 2016-07-28 10:24:32:297700
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 23.651815056422443

----------------------------

Covering trip times from 2016-07-28 10:24:32:345600 to 2016-07-28 10:25:02:344700
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 30.59743440617218

----------------------------

Covering trip times from 2016-07-28 10:25:02:398500 to 2016-07-28 10:25:32:397500
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 90.95069431637675

----------------------------

Covering trip times from 2016-07-28 10:25:32:443300 to 2016-07-28 10:25:50:043200
No resampling is required as time points of both dataframe are identical
Average Centroid Distane of cluster is 281.22142044903006